//
//  XJStatusToolBar.swift
//  新浪微博
//
//  Created by 徐绩 on 16/4/20.
//  Copyright © 2016年 ayumi. All rights reserved.
//

import UIKit

class XJStatusToolBar: UIView {

    override init(frame: CGRect) {
        
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /**
     布局界面
     */
    private func setupUI() {
    
        let retweetBtn = addChildBtn("转发", imageName: "timeline_icon_retweet")
        let commentBtn = addChildBtn("评论", imageName: "timeline_icon_comment")
        let likeBtn = addChildBtn("赞", imageName: "timeline_icon_unlike")
        
        let sp1 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        let sp2 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        addSubview(sp1)
        addSubview(sp2)
        
        retweetBtn.snp_makeConstraints { (make) -> Void in
            make.leading.top.bottom.equalTo(self)
            make.width.equalTo(commentBtn)
        }
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetBtn.snp_trailing)
            make.top.bottom.equalTo(self)
            make.width.equalTo(likeBtn)
        }
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.trailing.bottom.top.equalTo(self)
            make.leading.equalTo(commentBtn.snp_trailing)
            make.width.equalTo(retweetBtn)
            
        }
        sp1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
    }
    
    private func addChildBtn(title: String, imageName: String) -> UIButton {
    
        let button = UIButton(textColor: UIColor.darkGrayColor(), fontSize: 14)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        addSubview(button)
        
        return button
    }

}
